<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="Page.Page"   %>
<%@ page import="java.util.*"%>
<%@ page import="GridCommodity.GridCommodity"%>
<%@ page import="GridCommodity.GridCommodityShow"%>
<script type="text/javascript" language="javaScript">
	function del(url,url2){

	if(confirm("确定要删除？")){
		alert(url);
		alert(url2);
		window.location.href = ("GridCommodityDelete.jsp?DealComID="+url+"&Path="+url2);
	}
	}
	function modify(url){
	window.location.href = ("GridCommodityModify.jsp?DealID="+url);
	}
</script>
<%
   //从数据库中去出结果集
   int currentRecord = 0;
   String DealComID2="";
   String jp="";
   String sql="";
   int k=0;
   int k1=0;
   String path2="";
   Page pager=new Page();
   String MemName=(String)session.getAttribute("user");
   GridCommodityShow db =new GridCommodityShow();
   ArrayList<GridCommodity> result =db.GCShow();
   pager.setPageSize(10);
   pager.setTotalRecord(result.size());
   pager.setTotalPage(result.size(),pager.getPageSize());
   //计算并设置分页的参数
   if(request.getParameter("currentRecord")!=null)
   {   
       currentRecord = Integer.parseInt(request.getParameter("currentRecord"));
       pager.setCurrentRecord(currentRecord);
       pager.setCurrentPage(currentRecord,pager.getPageSize());
   }
   //从结果集中取出当前页面要显示的子集
   List<GridCommodity>subResult = null;
   if(currentRecord == 0)
   {
       if(currentRecord+pager.getPageSize()<=result.size())
       {
            subResult = result.subList(0,pager.getPageSize());
       }
       else
       {
       	   	subResult = result.subList(0,result.size());
       }
   
   }
   else if(pager.getCurrentRecord()+pager.getPageSize()<result.size())
       subResult = result.subList(pager.getCurrentRecord(),pager.getCurrentRecord

()+pager.getPageSize());
   else
       subResult = result.subList(pager.getCurrentRecord(),result.size());
%>
<html>
  <head>
    <title>格子中商品分页显示</title>
  </head>
  <body>
    <form name="From1" method="POST" action="GridCommodityShow.jsp">
	  	<table width="1000" border="20" height="600" align=center>
	  	<tr height="10" valign=top border="10"><td align=center>用户<%=MemName%>上传商品展示</td></tr>
	  	<tr>
	  	<td>
	  	<table>
	  	<%
   			 if(subResult.isEmpty()==false)
		       {
		             for(int i=0;i<subResult.size();i++)
		             {
		            	 GridCommodity GridCommodity = subResult.get(i);
		            	 String saveurl=request.getRealPath("/")+GridCommodity.getComImage();
		            	 if(i%5==0)
		            	 {
		            		 out.print("<tr  height=289 align=left valign=top>");
		            	 }
		                 out.print("<td width=180 border=1>");
		            	 out.print("<table width=160 border=1>");
		            	 out.print("<tr align=left valign=top >");
		            	 out.print("<td width=160>");
		            	 out.print("<a href='GridCommodityDetailed.jsp?jp="+"GridCommodityDeal.jsp"+"&GridComID="+GridCommodity.getComID()+"'>");
		            	 out.print("<img border=0 width=150 height=200 src=");
		            	 out.print("../"+GridCommodity.getComImage());
		            	 out.print("></a>");
		                 out.print("</td>");
		                 %>
		                 <tr><td align=center><input type= "button" value="编辑"   onclick="modify('<%=GridCommodity.getComID()%>')"></td></tr>
		                
		                 <tr><td align=center><input type= "button" value="删除"   onclick="del('<%=GridCommodity.getComID()%>','<%=GridCommodity.getComImage()%>')"></td></tr></table></td>
		                 <%
		                 if(i%5==4)
		                 {
		                	 out.print("</tr>");
		                 }
		             }
		        }
   		 %>
   		 </table>
   		 </td>
   		 </table >
   		 <table width="900" border="20" height="15" align=center >
   		 <tr valign="bottom"  algin=center >
   		 <font size="3">总<%=pager.getTotalRecord()%>条记录|总<%=pager.getTotalPage()%>页|当

		前<%=pager.getCurrentPage()+1%>页|每页<%=pager.getPageSize()%>条|
		<% 
		    //如果已经到了首页就去掉前一页的链接
		    if(pager.getCurrentRecord()-pager.getPageSize()<0)
		        out.println("首页|");
		    else
		    //上一页就是把当前记录位置减去一页显示记录的条数
		        out.print("<a href='GridCommodityDeal.jsp?currentRecord="+(pager.getCurrentRecord()-
		
		pager.getPageSize())+"&pageSize="+pager.getPageSize()+"'>上一页</a>|");
		    //如果到了尾页就去掉下一页的链接
		    if(pager.getCurrentRecord()+pager.getPageSize()>=pager.getTotalRecord())
		        out.println("尾页");
		    else
		    //下一页就是把当前记录位置加上一页显示记录的条数
		        out.print("<a href='GridCommodityDeal.jsp?currentRecord="+(pager.getCurrentRecord
		
		()+pager.getPageSize())+"&pageSize="+pager.getPageSize()+"'>下一页</a>|"); 
		%>
	</font></span>
	</table>
  	</form>	
  </body>
</html>
